/*
 * Created by JFormDesigner on Sun Jun 05 19:56:18 CST 2022
 */

package jw3.c10.view;

import java.awt.event.*;
import jw3.c10.controllner.RoleController;
import jw3.c10.controllner.StationController;
import jw3.c10.model.Role;
import jw3.c10.model.Station;

import java.awt.*;
import java.util.List;
import javax.swing.*;

/**
 * @author Brainrain
 */
public class Rlogin extends JFrame {
    public Rlogin() {
        initComponents();
        this.add(label1);
        this.add(label2);
        this.add(label3);
        this.add(comboBox1);
        this.add(comboBox2);
        this.add(comboBox3);
        this.add(button1);
        this.setBounds(400,400,800,600);
        label1.setBounds(29,25,200,40);
        comboBox1.setBounds(190,20,190,40);
        label2.setBounds(35,155,160,30);
        comboBox2.setBounds(160,155,130,35);
        label3.setBounds(295,155,160,30);
        comboBox3.setBounds(420,155,130,30);
        dialog1.setBounds(300,300,500,300);
        button1.setText("确定");
        label4.setBounds(10,20,220,20);
        label5.setBounds(200,-20,100,100);
        button1.setBounds(200,450,80,30);
        button3.setBounds(330,450,80,30);
        button6.setBounds(450,20,100,30);
        this.setTitle("线路站点选择");
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }


    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
//        String a= comboBox2.getSelectedItem().toString();
//        String b=comboBox3.getSelectedItem().toString();
//        int c=StationController.getSID(a);
//        int d=StationController.getSID(b);
//        int sorce=(d-c);
        int a=comboBox2.getSelectedIndex()+1;
        int b=comboBox3.getSelectedIndex()+1;
        if (Math.abs(b-a)<7) {
            label5.setText("" +Math.abs(b-a) + "元");
            dialog1.setModal(true);
            dialog1.setVisible(true);
        }else {
            label5.setText("7元");
            dialog1.setModal(true);
            dialog1.setVisible(true);
        }




    }

    private void comboBox1ItemStateChanged(ItemEvent e) {
        // TODO add your code here
        String Rname=comboBox1.getSelectedItem().toString();
        int r=RoleController.getRID(Rname);
        List<Station> list1=StationController.getAll(r);
        comboBox2.removeAllItems();
        comboBox3.removeAllItems();
        for (int i = 0; i < list1.size(); i++) {
            comboBox2.addItem(list1.get(i).getStation());
            comboBox3.addItem(list1.get(i).getStation());
        }
    }

    private void button4MouseClicked(MouseEvent e) {
        // TODO add your code here
        dialog1.dispose();
    }

    private void button5MouseClicked(MouseEvent e) {
        // TODO add your code here
        dialog1.dispose();
    }

    private void button6MouseClicked(MouseEvent e) {
        // TODO add your code here
        SPlogin sPlogin=new SPlogin();

    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        comboBox1 = new JComboBox();
        label2 = new JLabel();
        label3 = new JLabel();
        comboBox2 = new JComboBox();
        comboBox3 = new JComboBox();
        button1 = new JButton();
        button3 = new JButton();
        button6 = new JButton();
        dialog1 = new JDialog();
        label4 = new JLabel();
        label5 = new JLabel();
        button4 = new JButton();
        button5 = new JButton();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8bf7\u9009\u62e9\u7ebf\u8def");
        contentPane.add(label1);
        label1.setBounds(35, 50, 95, label1.getPreferredSize().height);

        //---- comboBox1 ----
        comboBox1.addItemListener(e -> comboBox1ItemStateChanged(e));
        contentPane.add(comboBox1);
        comboBox1.setBounds(155, 43, 135, comboBox1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u8bf7\u9009\u62e9\u5165\u7ad9\u53e3");
        contentPane.add(label2);
        label2.setBounds(45, 260, 110, label2.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u8bf7\u9009\u62e9\u5165\u7ad9\u53e3");
        contentPane.add(label3);
        label3.setBounds(260, 260, 110, 17);
        contentPane.add(comboBox2);
        comboBox2.setBounds(new Rectangle(new Point(155, 253), comboBox2.getPreferredSize()));
        contentPane.add(comboBox3);
        comboBox3.setBounds(new Rectangle(new Point(380, 253), comboBox3.getPreferredSize()));

        //---- button1 ----
        button1.setText("\u786e\u5b9a");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(135, 420), button1.getPreferredSize()));

        //---- button3 ----
        button3.setText("\u8fd4\u56de");
        contentPane.add(button3);
        button3.setBounds(345, 420, 78, 30);

        //---- button6 ----
        button6.setText("\u666f\u70b9\u63a8\u8350");
        button6.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button6MouseClicked(e);
            }
        });
        contentPane.add(button6);
        button6.setBounds(405, 35, 110, button6.getPreferredSize().height);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());

        //======== dialog1 ========
        {
            Container dialog1ContentPane = dialog1.getContentPane();
            dialog1ContentPane.setLayout(null);

            //---- label4 ----
            label4.setText("\u60a8\u672c\u6b21\u4e58\u5750\u5730\u94c1\u6d88\u8d39\u4e3a");
            dialog1ContentPane.add(label4);
            label4.setBounds(20, 35, 150, label4.getPreferredSize().height);

            //---- label5 ----
            label5.setText("text");
            dialog1ContentPane.add(label5);
            label5.setBounds(180, 35, 45, label5.getPreferredSize().height);

            //---- button4 ----
            button4.setText("\u786e\u5b9a");
            button4.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button4MouseClicked(e);
                }
            });
            dialog1ContentPane.add(button4);
            button4.setBounds(new Rectangle(new Point(75, 180), button4.getPreferredSize()));

            //---- button5 ----
            button5.setText("\u8fd4\u56de");
            button5.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    button5MouseClicked(e);
                }
            });
            dialog1ContentPane.add(button5);
            button5.setBounds(190, 180, 78, 30);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < dialog1ContentPane.getComponentCount(); i++) {
                    Rectangle bounds = dialog1ContentPane.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = dialog1ContentPane.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                dialog1ContentPane.setMinimumSize(preferredSize);
                dialog1ContentPane.setPreferredSize(preferredSize);
            }
            dialog1.pack();
            dialog1.setLocationRelativeTo(dialog1.getOwner());
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        List<Role> list=RoleController.getselect();
        for (int i = 0; i < list.size(); i++) {
            comboBox1.addItem(list.get(i).getRName());
        }


    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JComboBox comboBox1;
    private JLabel label2;
    private JLabel label3;
    private JComboBox comboBox2;
    private JComboBox comboBox3;
    private JButton button1;
    private JButton button3;
    private JButton button6;
    private JDialog dialog1;
    private JLabel label4;
    private JLabel label5;
    private JButton button4;
    private JButton button5;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

}
